import Mock from 'mockjs';

const Random = Mock.Random

let Result = {
    code: 200,
    msg : '操作成功',
    data: {

    }
}

/**
 * Mocl.mock( url, post/get , function(options) );
 * url, 表示需要拦截的URL
 * post/get 需要拦截的请求类型
 * 
 */

/**
 * 获取验证码图片以及一个随机码
 * 
 */
Mock.mock('/mock/captcha', 'get', ()=>{
    Result.data = {
        token: Random.string(30), // 获取一个32位的随机字符串
        captchaImg: Random.dataImage("120x40", Random.string(5))// 生成验证码位89564的base64图片编码
    }
    return Result;
})

Mock.mock(RegExp('/mock/login*'), 'post', (config: String) => {
    console.log("mock-----------login");
    return Result;
})

Mock.mock('/mock/sys/userInfo', 'get', (config: String) => {
    Result.data = {
        id: '001',
        username: '小明',
        avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
    }
    return Result;
})

Mock.mock('/mock/logout', 'get', (config: String) => {
    console.log("mock-----------logout");
    return Result;
})

Mock.mock('/mock/sys/menu/nav', 'get', (config: String) => {
    console.log("mock-----------nav");
    return Result;
})
